/*
ID: khymill1
PROG: numtri
LANG: C++
*/
#include <string.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>
using namespace std;

int main()
{
    ifstream fin("numtri.in");
    ofstream fout("numtri.out");
    int num;
	fin >> num;
	vector<vector<int> > arr;
	for (int i = 0; i < num; i++) {
		vector<int> input;
		for (int j = 0; j <= i; j++) {
			int tmp;
			fin >> tmp;
			input.push_back(tmp);
		}
		arr.push_back(input);
	}
	vector<vector<int> > dp;
	for (int i = 1; i < num; i++) {
		arr[i][0] += arr[i-1][0];
		arr[i][arr[i].size()-1] += arr[i-1][arr[i-1].size()-1];
		for (int j = 1; j < arr[i].size()-1; j++) {
			int a = arr[i][j] + arr[i-1][j-1];
			int b = arr[i][j] + arr[i-1][j];
			arr[i][j] = max(a,b);
		}
	}

	int rtn = 0;
	for (int i = 0; i < arr[num-1].size(); i++)
		if (rtn < arr[num-1][i])
			rtn = arr[num-1][i];


    return 0;
}                              